package com.smartwebx.ha.biz.assign.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartwebx.ha.biz.assign.HaDirectoryManager;
import com.smartwebx.ha.dal.assign.bean.HaDirectory;
import com.smartwebx.ha.dal.assign.bean.HaDirectoryExample;
import com.smartwebx.ha.dal.assign.bean.HaDirectoryExample.Criteria;
import com.smartwebx.ha.dal.assign.dao.HaDirectoryMapper;
/**
 * 
 * 创建人：Dream~天涯 
 * 创建时间：2015-4-21 下午8:08:27
 * 邮箱：154494796@qq.com
 * 备注：
 */
@Service
public class HaDirectoryManagerImpl implements HaDirectoryManager{
	@Autowired
	private HaDirectoryMapper haDirectoryMapper;
	@Override
	public int insert(HaDirectory haDirectory) {
		return this.haDirectoryMapper.insertSelective(haDirectory);
	}
	@Override
	public int update(HaDirectory haDirectory) {
		return this.haDirectoryMapper.updateByPrimaryKeySelective(haDirectory);
	}
	@Override
	public int delete(int organizeIds) {
		return this.haDirectoryMapper.deleteByPrimaryKey(organizeIds);
	}
	@Override
	public HaDirectory select(int organizeIds) {
		return this.haDirectoryMapper.selectByPrimaryKey(organizeIds);
	}
	@Override
	public Integer getReportId(Integer haDriectoryId) {
		HaDirectoryExample haDirectoryExample = new HaDirectoryExample();
		Criteria haDirectorycriteria = haDirectoryExample.createCriteria();
		haDirectorycriteria.andReportIdEqualTo(haDriectoryId);
		List<HaDirectory> haDirectorys = haDirectoryMapper.selectByExample(haDirectoryExample);
		return haDirectorys.get(0).getReportId();
	}
	@Override
	public Integer getReportId(String haDriectoryId) {
		HaDirectoryExample haDirectoryExample = new HaDirectoryExample();
		Criteria haDirectorycriteria = haDirectoryExample.createCriteria();
		if(haDriectoryId.indexOf("U")>=0||haDriectoryId.indexOf("D")>=0){
			haDirectorycriteria.andIdEqualTo(Integer.parseInt(haDriectoryId.substring(1, haDriectoryId.length())));
		}else{
			haDirectorycriteria.andReportIdEqualTo(Integer.parseInt(haDriectoryId.substring(1, haDriectoryId.length())));
		}
		List<HaDirectory> haDirectorys = haDirectoryMapper.selectByExample(haDirectoryExample);
		return haDirectorys.get(0).getReportId();
	}

	@Override
	public List<HaDirectory> getDirectoryFromCodeAndIsLeaf(String code,
			Integer isLeaf) {
		HaDirectoryExample haDirectoryExample = new HaDirectoryExample();
		Criteria haDirectorycriteria = haDirectoryExample.createCriteria();
		haDirectorycriteria.andCodeEqualTo(code);
		haDirectorycriteria.andIsLeafEqualTo(isLeaf);
		List<HaDirectory> haDirectorys = haDirectoryMapper.selectByExample(haDirectoryExample);
		return haDirectorys;
	}

	@Override
	public List<HaDirectory> getDirectoryData(String type, Integer param1, Integer reportType) {
		List<HaDirectory> haDirectory = null;
		HaDirectoryExample haDirectoryExample = new HaDirectoryExample();
		Criteria haDirectorycriteria = haDirectoryExample.createCriteria();
		int notReportType = 0;
		if(reportType==1){
			notReportType = 2;
		}else if(reportType==2){
			notReportType = 1;
		}
		if("reportId".equals(type)){
			haDirectorycriteria.andReportIdEqualTo(param1);
			haDirectorycriteria.andReportTypeNotEqualTo(notReportType);
		}else if("parentId".equals(type)){
			haDirectorycriteria.andParentIdEqualTo(param1);
			haDirectorycriteria.andReportTypeNotEqualTo(notReportType);
		}else if("reportType".equals(type)){
			haDirectorycriteria.andReportTypeEqualTo(param1);
		}
		haDirectory = haDirectoryMapper.selectByExample(haDirectoryExample);
		return haDirectory;
	}
	@Override
	public List<HaDirectory> getDirectoryData(String type, Integer param1) {
		List<HaDirectory> haDirectory = null;
		HaDirectoryExample haDirectoryExample = new HaDirectoryExample();
		Criteria haDirectorycriteria = haDirectoryExample.createCriteria();
		int notReportType = 0;
		if("reportId".equals(type)){
			haDirectorycriteria.andReportIdEqualTo(param1);
			haDirectorycriteria.andReportTypeNotEqualTo(notReportType);
		}else if("parentId".equals(type)){
			haDirectorycriteria.andParentIdEqualTo(param1);
			haDirectorycriteria.andReportTypeNotEqualTo(notReportType);
		}else if("reportType".equals(type)){
			haDirectorycriteria.andReportTypeEqualTo(param1);
		}
		haDirectory = haDirectoryMapper.selectByExample(haDirectoryExample);
		return haDirectory;
	}
}
